package com.wx.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.wx.constant.MessageConstant;
import com.wx.entity.PageResult;
import com.wx.entity.QueryPageBean;
import com.wx.entity.Result;
import com.wx.pojo.Setmeal;
import com.wx.service.SetmealService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 移动端套餐控制层
 */
@RestController
@RequestMapping("/setmeal")
public class MseatmealController {
    @Reference
    private SetmealService service;
    @RequestMapping("/getSetmeal")
    public Result getSeatmeal(){
        try {
            QueryPageBean queryPageBean = new QueryPageBean();
            queryPageBean.setQueryString("");
            queryPageBean.setCurrentPage(1);
            queryPageBean.setPageSize(100000);
            PageResult allSetmeal = service.findAllSetmeal(queryPageBean);
            List rows = allSetmeal.getRows();
            return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS,rows);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true, MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }
    @RequestMapping("/findById")
    public Result findById(Integer id){
        try {
            Setmeal setmealById = service.getSetmealById(id);
            return new Result(true,MessageConstant.QUERY_SETMEAL_SUCCESS,setmealById);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true,MessageConstant.QUERY_SETMEAL_FAIL);
        }

    }
}
